package com.housekeeping.housekeeping.order.dao.impl;

import com.housekeeping.housekeeping.order.dao.TradeDao;
import com.housekeeping.housekeeping.order.entity.OrderTrade;
import com.housekeeping.housekeeping.utils.DBManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TradeDaoImpl implements TradeDao {

    @Override
    public OrderTrade getTradeContent(String sid) throws SQLException {
        Connection conn = null;
        PreparedStatement pStmt = null;
        ResultSet rs = null;
        OrderTrade orderTrade = null;
        try {
            conn = DBManager.getConnection();
            String sql = "select * from order_trade where sid = ?";
            pStmt = conn.prepareStatement(sql);
            pStmt.setString(1, sid);
            rs = pStmt.executeQuery();
            while (rs.next()) {
                orderTrade = new OrderTrade();
                orderTrade.setTid(rs.getString("tid"));
                orderTrade.setPaidTime(rs.getDate("paid_time"));
                orderTrade.setTotalMoney(rs.getLong("total_money"));
                orderTrade.setSid(rs.getString("sid"));
                orderTrade.setIsDelete(rs.getInt("is_delete"));

            }
        } finally {
            DBManager.close(rs, pStmt, conn);
        }
        return orderTrade;
    }
}
